#include<cstdio>
int n,m;
long long comb(int x){return (long long)x*(x-1)*(x-2)/6;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
    scanf("%d%d",&n,&m);
    n++;m++;
    long long ans=comb(n*m)-n*comb(m)-m*comb(n);
    for(int i=1;i<n;++i)
    {
        for(int j=1;j<m;++j)
        {
            int d=gcd(i,j);
            if(d)ans-=(long long)(d-1)*2*(n-i)*(m-j);
        }
    }
    printf("%lld\n",ans);
    return 0;
}
